package com.loan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.loan.exeception.AppException;
import com.loan.exeception.AppExceptionCodeMsg;
import com.loan.mapper.MeasureMapper;
import com.loan.entity.Measure;
import com.loan.service.MeasureService;
import com.loan.service.SendSmsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author z
* @description 针对表【measure】的数据库操作Service实现
* @createDate 2023-04-21 14:51:41
*/
@Service
public class MeasureServiceImpl extends ServiceImpl<MeasureMapper, Measure> implements MeasureService {

    @Resource
    private MeasureMapper measureMapper;
    @Resource
    private SendSmsService sendSmsService;
    @Override
    public Measure addMeasure(Measure measure) {
        //验证码比对
        boolean b = sendSmsService.checkSms(measure.getPhone(), measure.getCode());
        if (b){
            int insert = measureMapper.insert(measure);
            if (insert != 1){
                throw new AppException(AppExceptionCodeMsg.MEASURE_INSERT_ERROR);
            }else {
                return measure;
            }
        }else {
            throw new AppException(AppExceptionCodeMsg.CODE_NUMBER_IS_ERROR);
        }
    }
}




